<?php
if(isset($_GET['category']) or isset($_GET['brand']) or isset($_GET['tag'])){
	//$pagename_arr = explode("/",$_SERVER['REDIRECT_URL']);
	//$pagename = $pagename_arr[count($pagename_arr)-1];
	
	$objGetRd	= new setPageTitle();
	$pageTitle	= $objGetRd->run();

}else{
	$pageTitle = "Men's clothing delivered all over China";
}

echo $pageTitle;


class setPageTitle extends Controller
{
	public function __construct()
	{
		parent::__construct();		
	}
	
	public function run()
	{
		$str  = $this->getPageTitle();
		return $str;
	}
	
	public function getPageTitle()
	{
		$this->import('Database');
		
		$pagename_arr = explode("/",$_SERVER['REDIRECT_URL']);
		$pagename = $pagename_arr[count($pagename_arr)-1];

		if($pagename=="product.html"){
			if(isset($_GET['id']) && $_GET['id'] != "") {
				$sql	= "SELECT name FROM `product_catalog` where id=".$_GET['id'];
				$Rd 		= $this->Database->prepare("$sql")
											 ->execute(time(), time()); 
				$Rd->next();
				$str = $Rd->name;
				return $str;
			}			
		}
		
		
		// Category Or Subcategory
		if(isset($_GET['category']) && $_GET['category'] != "") {
			$sql	= "SELECT a.id, a.name, b.name AS bname
						FROM `tl_taxonomy` AS a
						LEFT JOIN `tl_taxonomy` AS b ON b.pid = a.id
						WHERE a.id =".$_GET['category']." OR b.id =".$_GET['category']."
						LIMIT 0 , 1";
			$Rd 		= $this->Database->prepare("$sql")
										 ->execute(time(), time()); 
			$Rd->next();
			if($Rd->id==$_GET['category']){
				$str = $Rd->name;
			}else{
				$str = $Rd->name." /// ".$Rd->bname;
			}
			return $str;
		}
		
		// set brand
		if(isset($_GET['brand']) && $_GET['brand'] != "") {
			$sql	= "SELECT brand FROM `catalog_brand` where id=".$_GET['brand'];
			$Rd 		= $this->Database->prepare("$sql")
										 ->execute(time(), time()); 
			$Rd->next();
			$str = $Rd->brand;
			return $str;
		}		
		
		// set tag
		if(isset($_GET['tag']) && $_GET['tag'] != "") {
			$sql	= "SELECT tag FROM `catalog_tags` where id=".$_GET['tag'];
			$Rd 		= $this->Database->prepare("$sql")
										 ->execute(time(), time()); 
			$Rd->next();
			$str = $Rd->tag;
			return $str;
		}		
	}
}
?>